using System;
using System.Collections.Generic;
using System.Text;

namespace SmartContentDB.Interfaces
{
    public class Field
    {
        #region Variables
        private string name;
        private string type;
        private bool is_nullable;
        private int length;
        #endregion

        #region Constructor
        public Field()
        {
            this.name = null;
            this.type = null;
        }
        public Field(string column_name, string column_type, string is_nullable)
        {
            this.name = column_name;
            string[] split = column_type.Split(new char[] { '(', ')' });
            this.type = split[0];
            this.length = int.Parse(split[1]);
            this.is_nullable = is_nullable.Equals("YES") ? true : false;
        }
        #endregion

        #region Set/Get
        public string getName()
        {
            return name;
        }
        public string getType()
        {
            return type;
        }

        public string getDBType()
        {
            if (type.ToUpper().Equals("DATETIME"))
                return type;
            else
                return type + "(" + length + ")";
        }
        public bool IsNullable()
        {
            return is_nullable;
        }

        public string getDBNULL()
        {
            if (is_nullable)
                return "DEFAULT NULL";
            else
                return "NOT NULL";
        }
        public int getLength()
        {
            return length;
        }
        #endregion
    }
}
